package webauto01;

import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.File;
import java.io.IOException;

public class WebTest02 {

    //断言
    @Test
    public void test01() throws InterruptedException, IOException {
        ChromeDriver chromeDriver = new ChromeDriver();
        chromeDriver.get("https://www.baidu.com");
        chromeDriver.manage().window().maximize();

        chromeDriver.findElement(By.cssSelector("#s-top-loginbtn")).click();
        Thread.sleep(2000);
        chromeDriver.findElement(By.cssSelector("#TANGRAM__PSP_11__userName")).sendKeys("13667865467");
        chromeDriver.findElement(By.cssSelector("#TANGRAM__PSP_11__password")).sendKeys("123");
        chromeDriver.findElement(By.cssSelector("#TANGRAM__PSP_11__isAgree")).click();
        chromeDriver.findElement(By.cssSelector("#TANGRAM__PSP_11__submit")).click();
        Thread.sleep(1000);
        String text = chromeDriver.findElement(By.cssSelector("#TANGRAM__PSP_11__error")).getText();

        System.out.println("实际："+ text);
        Assertions.assertEquals("用户名或密码有误，请重新输入或找回密码",text);

        File a = chromeDriver.getScreenshotAs(OutputType.FILE);
        File b = new File("C:\\Users\\20182\\Desktop\\error-img\\login-error.png");
        FileUtils.copyFile(a,b);
        chromeDriver.quit();
    }
}
